package org.linlinjava.litemall.wx.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.dto.QcodeDto;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.dto.ActivityGrouponDto;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.service.WxActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ： hejiaming
 * @createtime ： 2021-03-18 11:58
 * @description ： 活动团购
 */
@RestController
@RequestMapping("/wx/activity")
@Validated
public class WxActivityController {

    private final Log logger = LogFactory.getLog(WxActivityController.class);

    @Autowired
    private WxActivityService wxActivityService;

    @PostMapping("/grouponList")
    public Object grouponList(@LoginUser Integer userId, @RequestBody ActivityGrouponDto dto) {
        if (userId == null) {
            return ResponseUtil.fail(900, "用户token失效");
        }
        return wxActivityService.activityGroups(dto, userId);
    }

    @PostMapping("/generateQCode")
    public Object generateQCode(@LoginUser Integer userId, @RequestBody QcodeDto dto) {
        return wxActivityService.generateQCode(userId, dto);
    }


    @PostMapping("/grouponListBySubject")
    public Object grouponListBySubject(@LoginUser Integer userId, @RequestBody ActivityGrouponDto dto) {
        return wxActivityService.grouponListBySubject(dto, userId);
    }
}
